﻿
/*
 * Javasript based on Functions(JBF) 1.03
 * 
 * Copyright(c) 2010, Fooxee (JA86.CN)
 *
 * JBF is licensed under the terms of the Open Source GPL 3.0(http://www.gnu.org/licenses/gpl.html) license. 
 * 
 * JBF's blog: http://www.cnblogs.com/JBF/
 * 
 * Created by Fooxee. at 2010.03.08  mailTo:hjccjun@163.com
 */

//Cookie操作
JBF.Cookie=JBF.cookie={
	//设置
	set:function(name, value/*expires,path,domain,secure*/)
	{
		var argv = arguments;
        var argc = arguments.length;
        var expires = (argc > 2) ? argv[2] : null;
		if(JBF.isNumber(expires))
			expires=new Date( new Date().getTime() + expires * 3600000);
        var path = (argc > 3) ? argv[3] : '/';
        var domain = (argc > 4) ? argv[4] : null;
        var secure = (argc > 5) ? argv[5] : false;
        document.cookie = name + "=" + escape(value) + ((expires === null) ? "" : ("; expires=" + expires.toGMTString())) + ((path === null) ? "" : ("; path=" + path)) + ((domain === null) ? "" : ("; domain=" + domain)) + ((secure === true) ? "; secure" : "");
		
	},
	//获取
	get:function(name)
	{
		var sRE = "(?:; )?" + name + "=([^;]*);?";
		var oRE = new RegExp(sRE);
		if (oRE.test(document.cookie))
		{
			return unescape(RegExp["$1"]);
		} 
		else
		{
			return null;
		}
	},
	//移除
	remove:function(name)
	{
		this.set(name,null,-9999*10);
	},
	//清除所有Cookie
	clear:function()
	{
		document.cookie=null;
	}
};
